/**  
* @Title: WechatUserInfoController.java
* @Package com.hjb.service.controller.Wechat
* @author <a href="mailto:125671254@qq.com">Pan Xinwen</a>panxinwen
* @date 2018年1月10日 下午11:41:20
* @version V1.0  
*/ 
package com.hjb.service.controller.Wechat;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.hjb.service.Wechat.WechatUserInfoService;
import com.hjb.service.annotation.LogInfo;
import com.hjb.service.annotation.LogType;
import com.hjb.service.config.constant.Key;
import com.hjb.service.domain.SiteUserOrder.SiteUserOrder;
import com.hjb.service.domain.siteuser.SiteUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
* @ClassName: WechatUserInfoController
* @Description: TODO(租户信息)
* @author <a href="mailto:125671254@qq.com">Pan Xinwen</a>panxinwen
* @date 2018年1月10日 下午11:41:20
*
*/
@RestController
@RequestMapping("/Wechat/userMsg")
@Api(value="/Wechat/userMsg",description="公众号端租户个人信息维护"	)
public class WechatUserInfoController {

	@Autowired
	private WechatUserInfoService wechatUserInfoService;
	
	@SuppressWarnings("rawtypes")
	@LogInfo(logType = LogType.查询, operationContent = "租户信息查询")
	@PostMapping("/getUser")
	@ResponseBody
	@ApiOperation("租户信息查询")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "租户ID", required = false)})
	
	public ResponseEntity getUser(@RequestParam(value = "userId", required = false) String userId){
		
		return ResponseEntity.ok(wechatUserInfoService.getUser(Integer.parseInt(userId)));
		
	}
	
	@SuppressWarnings("rawtypes")
	@LogInfo(logType=LogType.修改,operationContent="租户信息维护")
	@PostMapping("/supplementUserMsg")
	@ResponseBody
	@ApiOperation(value="租户信息维护", notes="租户信息维护")
	@ApiImplicitParams({ 
		@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "租户ID", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "linkmanType", value = "紧急联系人关系：1父母；2配偶；3朋友；3同事；", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "linkman", value = "紧急联系人姓名", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "linkmanMobile", value = "紧急联系人电话", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "email", value = "公司邮箱", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "company", value = "公司名称", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "companyAddress", value = "公司 地址", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "dptStatus", value = "工作状态：1:在职；2在校 3刚毕业无工作4其他", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "String", name = "job", value = "职位", required = true),
		@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "income", value = "收入", required = true)
		})
	public ResponseEntity supplementUserMsg(
			@RequestParam(value = "userId", required = true) Integer userId,
			@RequestParam(value = "linkmanType", required = true) Integer linkmanType,
			@RequestParam(value = "linkman", required = true) String linkman,
			@RequestParam(value = "linkmanMobile", required = true) String linkmanMobile,
			@RequestParam(value = "email", required = true) String email,
			@RequestParam(value = "company", required = true) String company,
			@RequestParam(value = "companyAddress", required = true) String companyAddress,
			@RequestParam(value = "job", required = true) String job,
			@RequestParam(value = "income", required = true) Integer income,
			@RequestParam(value = "dptStatus", required = true) Integer dptStatus
			){
		SiteUser siteUser = new SiteUser();
		siteUser.setUserId(userId);
		siteUser.setLinkmanType(linkmanType);
		siteUser.setLinkman(linkman);
		siteUser.setLinkmanMobile(linkmanMobile);
		siteUser.setEmail(email);
		siteUser.setCompany(company);
		siteUser.setCompanyAddress(companyAddress);
		siteUser.setDptStatus(dptStatus);
		siteUser.setJob(job);
		siteUser.setIncome(income);

		return ResponseEntity.ok(wechatUserInfoService.supplementUserMsg(siteUser));
	}
	
//	  @LogInfo(logType=LogType.查询,operationContent="租户身份证上传")
//	  @PostMapping("/upload")
//	  @ResponseBody
//	  @ApiOperation(value="租户身份证上传", notes="租户身份证上传")
//	  @ApiImplicitParams({ 
//		@ApiImplicitParam(paramType = "form", dataType = "String", name = "orderId", value = "订单号",defaultValue="20180113120927100000",required = true),
//		@ApiImplicitParam(paramType = "form", dataType = "File", name = "fileContract", value = "合同照片", required = true),
//		@ApiImplicitParam(paramType = "form", dataType = "File", name = "fileRenter", value = "租户身份证照片", required = true),
//		@ApiImplicitParam(paramType = "form", dataType = "File", name = "fileHouse", value = "房产证证照片", required = true),
//		@ApiImplicitParam(paramType = "form", dataType = "File", name = "fileAgent", value = "代理合同照片", required = true)
//		})
//	  public ResponseEntity upload(MultipartHttpServletRequest request) throws IOException, Exception {
//		String doc = "http://image.toohui.com/";
//		String orderId = request.getParameter("orderId");
//		//查询订单信息
//		SiteUserOrder updateOrder = new SiteUserOrder();
//		updateOrder.setId(orderId);  
//	    String resultCode = "200";
//	    String resultMsg = "上传成功";
//	    
//		String filePath = "E:\\测试文件目录\\files\\";
//		String fileName = "";
//		MultipartFile contract_file = ((MultipartHttpServletRequest) request).getFile("fileContract");
//		if(contract_file==null) {
//			resultCode = "201";
//			resultMsg = "合同照片为空";
//		}else {
//			fileName = getFileName(contract_file.getOriginalFilename());
//			uploadFile(contract_file.getBytes(), filePath, fileName);
//			updateOrder.setOrderUrl(doc+fileName);
//		}
//		
//		MultipartFile renter_file = ((MultipartHttpServletRequest) request).getFile("fileRenter");
//		if(renter_file==null) {
//			resultCode = "202";
//			resultMsg = "租户身份证照片为空";
//		}else {
//			fileName = getFileName(renter_file.getOriginalFilename());
//			uploadFile(renter_file.getBytes(), filePath, fileName);
//			updateOrder.setOwnerUrl(doc+fileName);
//		}
//		
//		
//		MultipartFile house_file = ((MultipartHttpServletRequest) request).getFile("fileHouse");
//		if(house_file==null) {
//			resultCode = "203";
//			resultMsg = "房产证照片为空";
//		}else {
//			fileName = getFileName(house_file.getOriginalFilename());
//			uploadFile(house_file.getBytes(), filePath, fileName);
//			updateOrder.setHouseUrl(doc+fileName);
//		}
//		
//		
//		MultipartFile agent_file = ((MultipartHttpServletRequest) request).getFile("fileAgent");
//		if(agent_file==null) {
//			resultCode = "204";
//			resultMsg = "代理合同照片为空";
//		}else {
//			fileName = getFileName(agent_file.getOriginalFilename());
//			uploadFile(agent_file.getBytes(), filePath, fileName);
//			updateOrder.setAgentUrl(doc+fileName);
//		}
//		
//	    siteUserOrderService.updateOrder(updateOrder);
//	    Map<String,Object> result = new HashMap<String,Object>();
//	    result.put(Key.RESULT_CODE, resultCode);
//	    result.put(Key.RESULT_INFO, resultMsg);
//	    return ResponseEntity.ok(result);
//	  }
	
}
